/**   
* @Title: ArchiveclassmanagerController.java 
* @Package avicit.im.lantop.basic.archiveclassmanager.controller 
* @Description: fixme(用一句话描述该文件做什么) 
* @author A18ccms A18ccms_gmail_com   
* @date 2014-9-23 下午1:40:40 
* @version V1.0   
*/
package avicit.im.lantop.basic.archiveclassmanager.action;

//import avicit.cbb.appreg.service.CommSysInfoIntfsService;
//import avicit.cbb.billdefine.service.BillDefineManagerIntfsService;
import avicit.cbb.billdefine.service.api.BillDefineManagerIntfsServiceApi;
import avicit.cbb.tabledefine.service.CommTableManagerIntfsService;
import avicit.cbb.tabledefine.service.api.CommTableManagerIntfsServiceApi;
import avicit.im.lantop.archiveplanmanager.archiveplanedit.service.api.ArchivePlanServiceApi;
import avicit.im.lantop.basic.archiveclassmanager.domain.LantopArchiveClass;
//import avicit.im.lantop.basic.archiveclassmanager.service.ArchiveclassmanagerService;
import avicit.im.lantop.basic.archiveclassmanager.service.api.ArchiveclassmanagerServiceApi;
//import avicit.im.lantop.common.service.CommonManagerIntfsService;
import avicit.im.lantop.common.service.api.CommonManagerIntfsServiceApi;
import avicit.platform6.api.application.SysApplicationAPI;
import avicit.platform6.api.session.SessionHelper;
import avicit.platform6.api.syslookup.SysLookupAPI;
import avicit.platform6.api.syslookup.dto.SysLookupSimpleVo;
import avicit.platform6.api.sysuser.SysUserAPI;
import avicit.platform6.api.sysuser.dto.SysUser;
import avicit.platform6.commons.utils.ComUtil;
import avicit.platform6.commons.utils.JsonHelper;
import avicit.platform6.commons.utils.JsonUtils;
import avicit.platform6.commons.utils.Pinyin4jUtil;
import avicit.platform6.commons.utils.RequestUtil;
import avicit.platform6.commons.utils.web.TreeNode;
import avicit.platform6.core.context.ThreadContextHelper;
import avicit.platform6.core.dao.Paging;
import avicit.platform6.core.properties.PlatformConstant;
import avicit.platform6.core.properties.PlatformConstant.OpResult;
import avicit.platform6.core.properties.PlatformConstant.OpType;
import avicit.platform6.modules.system.syslog.service.LogBaseFactory;
import avicit.platform6.modules.system.syslog.service.SysLogUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.util.*;

/** <p>金航数码科技有限责任公司</p>
 * <p>作者：钟一华</p>
 * <p>邮箱：feifan1985@163.com</p>
 * <p>创建时间： 2014-9-23 下午1:40:40 </p>
 * <p>类说明：archiveclassmanager模块控制层</p>
 * <p>修改记录： </p> 
 */
@Controller
@SuppressWarnings({"unchecked","deprecation"})
@RequestMapping("/archiveclassmanagerController")
public class ArchiveclassmanagerController {

	@Resource
	private ArchiveclassmanagerServiceApi archiveclassmanagerService;

	@Autowired
	private ArchivePlanServiceApi archivePlanService;

	@Resource
	private CommSysInfoIntfsService commSysInfoIntfsService;

	@Autowired(required = false)
	private CommTableManagerIntfsServiceApi commTableManagerIntfsService;

	@Autowired(required = true)
	private BillDefineManagerIntfsServiceApi billDefineManagerIntfsService;
	
	@Autowired(required = true)
	private SysApplicationAPI sysApplicationAPI;
	
	@Autowired(required = false)
	private CommonManagerIntfsServiceApi commonManagerIntfsServiceImpl;

	@Autowired
	private SysUserAPI sysUserAPI;

	@Autowired
	private SysLookupAPI sysLookupAPI;

	/**
	 * 获得树形数据
	 * @author 钟一华 
	 * @param id
	 * @param response
	 * @return
	 * @throws Exception ModelAndView
	 * @throws
	 */
	@RequestMapping("/findChildsByNodeId")
	@ResponseBody
	public Map<String,Object> findChildsByNodeId(String id, HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String value = request.getParameter("value");
		if (null != value && !"".equals(value)) {
			value = URLDecoder.decode(value, "utf-8");
		}
		String orgId = ThreadContextHelper.getOrgId();
		String deptId = ThreadContextHelper.getDeptId();
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		List<TreeNode> nodes = new ArrayList<TreeNode>();
		try {
			// List<String> paths = this.archiveclassmanagerService.getNodePathsByNodeName(value);
			int level = 1;
			if (StringUtils.isEmpty(id)) {
				id = "ROOT";
				level = 3;
			}
			// Map<String, Object> param = new HashMap<String, Object>();
			// param.put("NODE_ID", "8a58bc5b4dffa2ee014dffaaa66f1304");
			// 测试接口用
			// nodes = this.archiveClassManagerIntfsService.getArchiveClassTreeNodeToDataNodeByIntfs(orgId, deptId, sysId, param);
			// 原方法
			nodes = this.archiveclassmanagerService.recurFindTreeNodesByParentId(id, orgId, deptId, level);
			map.put("result", OpResult.success.ordinal());
		} catch (Exception e) {
			map.put("result", OpResult.failure.ordinal());
			map.put("msg", "后台处理异常, " + e.getMessage());
		}
		map.put("data", nodes);
		return map;
	}

	/**
	 * 获得树形数据
	 * @author 钟一华 
	 * @param id
	 * @param response
	 * @return
	 * @throws Exception ModelAndView
	 * @throws
	 */
	@RequestMapping("/searchTreeNode")
	@ResponseBody
	public Map<String,Object> searchTreeNode(String id, HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String orgId = ThreadContextHelper.getOrgId();
		String deptId = ThreadContextHelper.getDeptId();
		String value = request.getParameter("value");
		if (null != value && !"".equals(value)) {
			value = URLDecoder.decode(value, "utf-8");
		}
		List<TreeNode> nodes = new ArrayList<TreeNode>();
		try {
			List<String> paths = this.archiveclassmanagerService.getNodePathsByNodeName(value);
			if (StringUtils.isEmpty(id)) {
				id = "ROOT";
			}
			if (null != value && !"".equals(value)) {
				nodes = this.archiveclassmanagerService.findSearchTreeNode(orgId, deptId, id, paths, value);
			} else {
				nodes = this.archiveclassmanagerService.recurFindTreeNodesByParentId(id, orgId, deptId, 3);
			}
			map.put("result", OpResult.success.ordinal());
		} catch (Exception e) {
			map.put("result", OpResult.failure.ordinal());
			map.put("msg", "后台处理异常, " + e.getMessage());
		}
		map.put("data", nodes);
		return map;
	}

	/**
	 * 获得所有通用代码数据
	 * @author 钟一华
	 * @return ModelAndView
	 * @throws
	 */
	@RequestMapping("/getAllLookupList")
	@ResponseBody
	public Map<String,Object> getAllLookupList(HttpServletRequest request, HttpServletResponse response) {
		Collection<SysLookupSimpleVo> archiveClassNodeTypeList = sysLookupAPI.getLookUpListByType("LANTOP_NODE_TYPE");
		Map<String,Object> map = new HashMap<>();
		map.put("archiveClassNodeTypeList", archiveClassNodeTypeList);
		map.put("loginName", SessionHelper.getLoginSysUser(request).getName());
		map.put("loginUserId", SessionHelper.getLoginSysUserId(request));
		return map;
	}

	/**
	 * 通过path获得pathName
	 * 获得最大表名
	 * @author 钟一华
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception ModelAndView
	 * @throws
	 */
	@RequestMapping("/getArchiveClassNodePathNameMaxTableName")
	@ResponseBody
	public Map<String,Object> getArchiveClassNodePathNameMaxTableName(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> maps = new HashMap<>();
		String id = request.getParameter("id");
		String path = request.getParameter("path");
		String createBy = request.getParameter("createBy");
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		try {
			Map<String,Object> map = this.archiveclassmanagerService.getPathNameByPath(path);
			String pathName = "";
			String attribute01="0";
			if(null != map.get("ARCHIVE_CLASS_PATH_NAME")){
				pathName=map.get("ARCHIVE_CLASS_PATH_NAME").toString();
			}
			if(null != map.get("ATTRIBUTE_01")){
				attribute01=map.get("ATTRIBUTE_01").toString();
			}
					
			String createByName = "";

			if (null != createBy && !"".equals(createBy)) {
				SysUser user = sysUserAPI.getSysUserById(createBy);
				createByName = user.getName();// 人员名称
			}
			// 获得最大表名
			String maxTableName = this.commTableManagerIntfsService.getCbbMaxTableNameByNodeIdByIntfs(ThreadContextHelper.getOrgId(), ThreadContextHelper.getDeptId(), sysId, id);
			maps.put("maxTableName", maxTableName);
			maps.put("pathName", pathName);
			maps.put("createByName", createByName);
			maps.put("attribute01", attribute01);
			maps.put("flag", OpResult.success.ordinal());
		} catch (Exception e) {
			maps.put("flag", OpResult.failure.ordinal());
			e.printStackTrace();
		}
		return maps;
	}

	/**
	 * 通过树形节点id获得树节点对应数据
	 * @author 钟一华
	 * @param request
	 * @return ModelAndView
	 * @throws
	 */
	@RequestMapping("/getArchiveClassById")
	@ResponseBody
	public Map<String,Object> getArchiveClassById(HttpServletRequest request) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String id = request.getParameter("id");
		LantopArchiveClass lantopArchiveClass = archiveclassmanagerService.getArchiveclassmanagerById(id);
		SysUser sysuser = sysUserAPI.getSysUserById(lantopArchiveClass.getCreatedBy());
		String createdByName = sysuser.getName();
		lantopArchiveClass.setCreatedByName(createdByName);
		map.put("lantopArchiveClass", lantopArchiveClass);
		return map;
	}

	/**
	 * 获得最大节点顺序值
	 * @author 钟一华
	 * @return ModelAndView
	 * @throws Exception ModelAndView
	 * @throws
	 */
	@RequestMapping("/getMaxaNodeSortNumber")
	@ResponseBody
	public Map<String,Object> getMaxNodeSortNumber(HttpServletRequest request) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String id = request.getParameter("id");
		int number = archiveclassmanagerService.getMaxNodeSortNumber(id);
		map.put("maxNumber", number);
		return map;
	}

	/**
	 * 保存新节点值
	 * @author 钟一华 
	 * @param request
	 * @param response
	 * @return ModelAndView
	 * @throws Exception ModelAndView
	 * @throws
	 */
	@RequestMapping("/addTreeNode")
	@ResponseBody
	public Map<String,Object> addTreeNode(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String orgId = ThreadContextHelper.getOrgId();
		String deptId = ThreadContextHelper.getDeptId();
		String sysId = request.getParameter("sysId");
		String loginUserId = SessionHelper.getLoginSysUserId(request);
		String loginIp = RequestUtil.getClientIp(request);
		sysId = "LANTOP";
		BigDecimal sortNumber = BigDecimal.valueOf(Long.parseLong(request.getParameter("sortNumber")));
		String datas = request.getParameter("data");
		LantopArchiveClass lac = (LantopArchiveClass) JsonHelper.getInstance().readValue(datas, LantopArchiveClass.class);
		try {
			boolean flag = this.archiveclassmanagerService.checkNodeNameByIntfs(lac.getParentId(), lac.getArchiveClassNodeName());
			if (flag) {
				map.put("flag", OpResult.failure.ordinal());
				map.put("msg", "该节点名称已存在,请重新输入!");
			} else {
				String id = ComUtil.getId();
				lac.setId(id);
				lac.setDeptId(deptId);
				lac.setOrgId(orgId);
				lac.setSysId(sysId);
				lac.setArchiveClassNodeCode(Pinyin4jUtil.getPinYinHeadChar(lac.getArchiveClassNodeName()));
				lac.setNodeSortNumber(sortNumber);
				String pathName = this.archiveclassmanagerService.getNodePathByParentId(lac.getParentId());
				pathName = pathName + "/" + id;
				lac.setArchiveClassNodePath(pathName);
				// this.archiveClassManagerIntfsService.createArchiveClassByIntfs(orgId, deptId, sysId, "测试创建节点接口1",
				// "8a58bc2248f7b9ff0148f8be72ab00a2/8a58bc2248f7b9ff0148f91762850119/8a58bcef493c653201493c72e961015e", "2");
				archiveclassmanagerService.saveTree(lac);
				map.put("id", id);
				// 如果节点类型是 数据节点,则执行下面操作
				if (lac.getArchiveClassNodeType().equals("2")) {
					List<LantopArchiveClass> modelList = this.archiveclassmanagerService.getModelData(lac.getParentId());
					LantopArchiveClass m = modelList.get(0);
					String modelId = m.getId();
					List<Map<String, Object>> tableIdsList = this.commTableManagerIntfsService.getCbbTableIdsByNodeIdByIntfs(orgId, deptId, sysId, modelId);
					for (int i = 0; i < tableIdsList.size(); i++) {
						Map<String, Object> tableMap = tableIdsList.get(i);
						String tableId = (String)tableMap.get("TABLE_ID");
						String tabFlag = (String)tableMap.get("TAB_FLAG");
						Map<String, Object> param = new HashMap<String, Object>();
						param.put("TAB_FLAG", tabFlag);
						this.commTableManagerIntfsService.createCbbTabNodeByIntfs(orgId, deptId, sysId, id, tableId, loginUserId, loginIp, param);
					}
				}
				map.put("flag", OpResult.success.ordinal());
			}
		} catch (Exception e) {
			e.printStackTrace();
			map.put("flag", OpResult.failure.ordinal());
			map.put("msg", "后台处理异常,请联系管理员!");
		}
		return map;
	}

	/**
	 * 删除选中节点,并删除选中节点的子节点
	 * @author 钟一华
	 * @param request
	 * @param response
	 * @return ModelAndView
	 * @throws Exception ModelAndView
	 * @throws
	 */
	@RequestMapping("/removeTreeNode")
	@ResponseBody
	public Map<String,Object> removeTreeNode(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String menuCode = request.getParameter("menuCode");
		String id = request.getParameter("id");
		String orgId = ThreadContextHelper.getOrgId();
		String deptId = ThreadContextHelper.getDeptId();
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		try {
			String appId = this.sysApplicationAPI.getCurrentAppId();
			String languageCode = SessionHelper.getCurrentUserLanguageCode(request);
			String modleName = this.commonManagerIntfsServiceImpl.getMenuNameByCodeByIntfs(menuCode, appId, languageCode);
			if (StringUtils.isEmpty(id)) {
				map.put("result", OpResult.failure.ordinal());
				map.put("msg", "参数不正确！");
				return map;
			}
			Assert.notNull(id, "id不能为空！");
			try {
				this.deleteAllDataByNodeId(orgId, deptId, sysId, id, "", modleName);
			}catch (Exception e){
				e.printStackTrace();
			}finally {
				this.archiveclassmanagerService.delTree(id, orgId, deptId, sysId);
			}
			map.put("result", OpResult.success.ordinal());
		} catch (Exception e) {
			e.printStackTrace();
			map.put("result", OpResult.failure.ordinal());
			map.put("msg", "后台处理异常,请联系管理员！");
		}
		return map;
	}

	/**
	 * 粘贴操作
	 * @author 钟一华
	 * @return ModelAndView
	 * @throws Exception ModelAndView
	 * @throws
	 */
	@RequestMapping("/pasteTreeData")
	@ResponseBody
	public Map<String,Object> pasteTreeData(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<>();
		// 需要复制的节点id
		String copyId = request.getParameter("copyId");
		// 需要复制到目标的节点id
		String parentId = request.getParameter("parentId");
		String orgId = ThreadContextHelper.getOrgId();
		String deptId = ThreadContextHelper.getDeptId();
		String sysId = request.getParameter("sysId");
		String userId = SessionHelper.getLoginSysUserId(request);
		String ip = RequestUtil.getClientIp(request);
		sysId = "LANTOP";
		// 节点对应数据信息
		// this.commSysInfoIntfsService.getCbbTableIdsByNodeIdByIntfs(sysId, copyId);
		// 循环处理
		// this.commSysInfoIntfsService.createCbbTabNodeByIntfs(sysId, nodeId, tableId);
		this.archiveclassmanagerService.saveCopyTreeData(parentId, copyId, orgId, deptId, sysId, userId, ip);
		map.put("result", OpResult.success.ordinal());
		map.put("msg", "复制成功!");
		return map;
	}

	/**
	 * 获取最大表名
	 * @author 钟一华
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception ModelAndView
	 * @throws
	 */
	@RequestMapping("/getMaxTableName")
	public ModelAndView getMaxTableName(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mav = new ModelAndView();
		String nodeId = request.getParameter("nodeId");
		String sysId = request.getParameter("sysId");
		sysId = "LANTOP";
		String orgId = SessionHelper.getCurrentOrgId(request);
		String deptId = SessionHelper.getCurrentDeptId(request);
		try {
			String maxTableName = this.commTableManagerIntfsService.getCbbMaxTableNameByNodeIdByIntfs(orgId, deptId, sysId, nodeId);
			mav.addObject("maxTableName", maxTableName);
			mav.addObject("flag", OpResult.success.ordinal());
		} catch (Exception e) {
			mav.addObject("flag", OpResult.failure.ordinal());
			e.printStackTrace();
		}
		return mav;
	}

	/**
	 * 判断目标节点是否存在重复数据
	 * @author 钟一华
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception ModelAndView
	 * @throws
	 */
	@RequestMapping("/isRepeatNode")
	@ResponseBody
	public Map<String,Object> isRepeatNode(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String copyId = request.getParameter("copyId");
		String parentId = request.getParameter("parentId");
		try {
			boolean isRepeat = this.archiveclassmanagerService.isRepeatNode(copyId, parentId);
			map.put("isRepeat", isRepeat);
			map.put("flag", OpResult.success.ordinal());
		} catch (Exception e) {
			map.put("flag", OpResult.failure.ordinal());
			e.printStackTrace();
		}
		return map;
	}

	/**
	 * 更新节点数据
	 * @author 钟一华
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception ModelAndView
	 * @throws
	 */
	@RequestMapping("/updateData")
	@ResponseBody
	public Map<String,Object> updateData(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String id = request.getParameter("id");
		String sortNo = request.getParameter("sortNo");
		String className = request.getParameter("className");
		String remark = request.getParameter("remark");
		String attribute01 = request.getParameter("attribute01");
		try {
			this.archiveclassmanagerService.updateData(id, sortNo, className, remark, attribute01);
			map.put("flag", OpResult.success.ordinal());
		} catch (Exception e) {
			map.put("flag", OpResult.failure.ordinal());
			e.printStackTrace();
		}
		return map;
	}

	/**
	 * 跳转排序页面
	 * @author 钟一华
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception ModelAndView
	 * @throws
	 */
	@RequestMapping("/toOrderJsp")
	public ModelAndView toOrderJsp(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mav = new ModelAndView();
		String parentId = request.getParameter("id");
		String sysId = request.getParameter("sysId");
		String dialogId = request.getParameter("dialogId");
		try {
			mav.addObject("dialogId", dialogId);
			mav.addObject("parentId", parentId);
			mav.addObject("sysId", sysId);
			mav.addObject("flag", OpResult.success.ordinal());
			mav.setViewName("avicit/im/lantop/basic/archiveclassmanager/ArchiveclassmanagerOrder");
		} catch (Exception e) {
			mav.addObject("flag", OpResult.failure.ordinal());
			e.printStackTrace();
		}
		return mav;
	}

	/**
	 * 通过父节点ID获得子节点数据
	 * @author 钟一华
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception ModelAndView
	 * @throws
	 */
	@RequestMapping("/getTreeDataByParentId")
	@ResponseBody
	public Map<String,Object> getTreeDataByParentId(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<>();
		String parentId = request.getParameter("parentId");
		String pageNo = request.getParameter("page");
		String pageSize = request.getParameter("rows");
		try {
			Paging<LantopArchiveClass> page = new Paging<LantopArchiveClass>();
			page.setPageNo(ComUtil.getPageNo(pageNo));
			page.setPageSize(ComUtil.getPageSize(pageSize));
			page = this.archiveclassmanagerService.getTreeDataByParentId(page, parentId);
			map.put("total", page.getTotalCount());
			map.put("rows", page.getResult());
			map.put("flag", OpResult.success.ordinal());
		} catch (Exception e) {
			map.put("total", 0);
			map.put("rows", null);
			map.put("flag", OpResult.failure.ordinal());
			e.printStackTrace();
		}
		return map;
	}

	/**
	 * 更新排序号
	 * @author 钟一华
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception ModelAndView
	 * @throws
	 */
	@RequestMapping("/updateOrderData")
	public Map<String,Object> updateOrderData(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> maps = new HashMap<>();
		String sysId = request.getParameter("sysId");
		String json = request.getParameter("datas");
		sysId = "LANTOP";
		List<Map<String, Object>> list = JsonUtils.newInstance().Json2Bean2DataGrid(json, ArrayList.class);
		try {
			for (int i = 0; i < list.size(); i++) {
				Map<String, Object> map = list.get(i);
				this.archiveclassmanagerService.updateData(map.get("id").toString(), map.get("nodeSortNumber").toString(), null, null,null);
			}
			maps.put("flag", OpResult.success.ordinal());
		} catch (Exception e) {
			maps.put("flag", OpResult.failure.ordinal());
			e.printStackTrace();
		}
		return maps;
	}

	/**
	 * 判断当前节点下是否存在数据
	 * @author 钟一华
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception ModelAndView
	 * @throws
	 */
	@RequestMapping("/checkTreeNodeIsExistData")
	public Map<String,Object> checkTreeNodeIsExistData(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> maps = new HashMap<>();
		String nodeId = request.getParameter("nodeId");
		String sysId = request.getParameter("sysId");
		String orgId = ThreadContextHelper.getOrgId();
		String deptId = ThreadContextHelper.getDeptId();
		sysId = "LANTOP";
		Map<String, Object> listParam = new HashMap<String, Object>();
		try {
			boolean isExist = false;
			// 所选节点对应物理表信息
			List<Map<String, Object>> allList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "");
			for (int i = 0; i < allList.size(); i++) {
				Map<String, Object> map = allList.get(0);
				String tableId = map.get("ID").toString();
				List<Map<String, Object>> dataList = this.billDefineManagerIntfsService.getTableFieldsAndDatasBySearchByOrderbyByIntfs(orgId, deptId, sysId, tableId, "1", "100",
						" AND NODE_ID = '" + nodeId + "'", listParam);
				if (dataList.size() > 0) {
					isExist = true;
					break;
				}
			}
			maps.put("isExist", isExist);
			maps.put("flag", OpResult.success.ordinal());
		} catch (Exception e) {
			maps.put("flag", OpResult.failure.ordinal());
			e.printStackTrace();
		}
		return maps;
	}

	/**
	 * 递归删除所有节点下关联的数据
	 * @author 钟一华
	 * @param orgId
	 * @param deptId
	 * @param sysId
	 * @param nodeId
	 * @param tableId
	 * @throws Exception void
	 * @throws
	 */
	public void deleteAllDataByNodeId(String orgId, String deptId, String sysId, String nodeId, String tableId, String menuName) throws Exception {
		List<Map<String, Object>> treeNodeIdList = this.commTableManagerIntfsService.getCbbTableInfoByNodeIdByIntfs(orgId, deptId, sysId, nodeId, "");
		//判断数据表关系是一级还是二级
		Map<String, Object> modelParam = new HashMap<String, Object>();
		modelParam.put("treeNodeList", treeNodeIdList);
		Map<String, Object> modelMap = this.archiveclassmanagerService.getDataNodeInfoByParam(modelParam);
		int dataCount = Integer.parseInt(modelMap.get("dataCount").toString());
		if (dataCount == 1) {
			Map<String, Object> paramsFile = new HashMap<String, Object>();
			paramsFile.put("level", "1");
			paramsFile.put("condition", " AND NODE_ID = '" + nodeId + "'");
			this.billDefineManagerIntfsService.deleteDatasByParamByIntfs(orgId, deptId, sysId, nodeId, paramsFile);
		}
		if (dataCount == 2) {
			Map<String, Object> paramsFile = new HashMap<String, Object>();
			paramsFile.put("level", "1");
			paramsFile.put("condition", " AND NODE_ID = '" + nodeId + "'");
			this.billDefineManagerIntfsService.deleteDatasByParamByIntfs(orgId, deptId, sysId, nodeId, paramsFile);
			Map<String, Object> paramsAn = new HashMap<String, Object>();
			paramsAn.put("level", "2");
			paramsAn.put("condition", " AND NODE_ID = '" + nodeId + "'");
			this.billDefineManagerIntfsService.deleteDatasByParamByIntfs(orgId, deptId, sysId, nodeId, paramsAn);
		}
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("modleName", menuName);
		String modleName = "XXX模块";
		if (null != menuName && !"".equals(menuName)) {
			modleName = menuName;
		}
		SysLogUtil.log(modleName, "批量删除记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
	}

	@RequestMapping("/moveNode")
	@ResponseBody
	public Map<String, Object> moveNode(String targetNodeId, String treeId) {
		Map<String, Object> param = new HashMap<>();
		param.put("targetNodeId", targetNodeId);
		param.put("treeId", treeId);
		Map<String, Object> resultMap = archivePlanService.moveNode(param);
		return resultMap;
	}


}
